package com.lz.football.module.guide.setting
{
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.GuideEvent;
	import com.lz.football.module.guide.IGuideSettingView;
	import com.lz.football.module.guide.setting.view.CountrySettingPanel;
	import com.lz.football.module.guide.setting.view.NameSettingPanel;
	import com.lz.football.module.guide.setting.view.PlaceSettingPanel;
	import com.lz.football.module.guide.setting.view.TeamIconSettingPanel;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import lz.controls.core.UIComponent;

	/**
	 *新手设置 
	 * @author lake
	 * 
	 */	
	public class GuideSettingView extends UIComponent implements IGuideSettingView
	{
		/**
		 * 名字选择
		 */		
		private var settingMC1 :MovieClip;
		/**
		 * 国家选择
		 */		
		private var settingMC2 :MovieClip;
		/**
		 * 队徽选择
		 */		
		private var settingMC3 :MovieClip;
		/**
		 * 位置选择
		 */		
		private var settingMC4 :MovieClip;
		/**
		 *背景 
		 */		
		private var bgMc		:MovieClip;
		/**
		 *名字选择面板 
		 */		
		private var nameSettingPanel :NameSettingPanel;
		/**
		 *国家选择 
		 */		
		private var countrySettingPanel 	:CountrySettingPanel;
		/**
		 * 队徽选择
		 */		
		private var teamIconSettingPanel 	:TeamIconSettingPanel;
		/**
		 *位置选择 
		 */		
		private var placeSettingPanel		:PlaceSettingPanel;
		/**
		 *一键创建按钮 
		 */		
		private var skinGuideBtn :SimpleButton;
		
		public function GuideSettingView()
		{
			super();
		}
		/**
		 * 初始化
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			_symbolSkin = Reflection.createInstance("com.football.guide.settingMc");
			skinGuideBtn = Reflection.createInstance("com.com.skin.guide.createClubBtn");
			this.addChild(_symbolSkin);
			settingMC1 = _symbolSkin.settingMC1;
			settingMC2 = _symbolSkin.settingMC2;
			settingMC3 = _symbolSkin.settingMC3;
			settingMC4 = _symbolSkin.settingMC4;
			bgMc	   = _symbolSkin.bgMc;
			nameSettingPanel = new NameSettingPanel();
			nameSettingPanel.initUI(settingMC1);
			countrySettingPanel = new CountrySettingPanel();
			countrySettingPanel.initUI(settingMC2);
			teamIconSettingPanel = new TeamIconSettingPanel();
			teamIconSettingPanel.initUI(settingMC3);
			placeSettingPanel = new PlaceSettingPanel();
			placeSettingPanel.initUI(settingMC4);
			bgMc.width = GlobalDef.GameStage.stageWidth;
			bgMc.height = GlobalDef.GameStage.stageHeight;
			resizeUI();
			addEvtListener();
			showNameSelectPanel();
		}
		/**
		 * 添加事件
		 * 
		 */		
		public function addEvtListener():void
		{
			GlobalDef.GameStage.addEventListener(Event.RESIZE,resizeHandler);
			skinGuideBtn.addEventListener(MouseEvent.CLICK,skinBthH);
		}
		/**
		 *窗口大小改变 
		 * @param e
		 * 
		 */		
		private function resizeHandler(e :Event):void
		{
			resizeUI();
		}
		/**
		 *一键创建 
		 * @param e
		 */		
		private function skinBthH(e :Event):void
		{
			AppEventDispatcher.getInstance().dispatchEvent(new GuideEvent(GuideEvent.QUK_CREATE_CLUB));
		}
		/**
		 *重设ui大小 
		 */		
		private function resizeUI():void
		{
			bgMc.width = GlobalDef.GameStage.stageWidth;
			bgMc.height = GlobalDef.GameStage.stageHeight;
			settingMC1.x = (GlobalDef.GameStage.stageWidth - settingMC1.width)/2;
			settingMC1.y = (GlobalDef.GameStage.stageHeight - settingMC1.height)/2;
			settingMC2.x = (GlobalDef.GameStage.stageWidth - 985)/2;
			settingMC2.y = (GlobalDef.GameStage.stageHeight - 250)/2;
			settingMC3.x = (GlobalDef.GameStage.stageWidth - settingMC3.width)/2;
			settingMC3.y = (GlobalDef.GameStage.stageHeight - settingMC3.height)/2;
			settingMC4.x = (GlobalDef.GameStage.stageWidth - settingMC4.width)/2;
			settingMC4.y = (GlobalDef.GameStage.stageHeight - settingMC4.height)/2;
			var parentX :Number = GlobalDef.GameStage.stageWidth - countrySettingPanel.nextBtn.width;
			var parentY :Number = GlobalDef.GameStage.stageHeight - countrySettingPanel.nextBtn.height;
			var locPoint :Point = settingMC2.globalToLocal(new Point(parentX,parentY));
			//countrySettingPanel.nextBtn.x = locPoint.x;
			//countrySettingPanel.nextBtn.y = locPoint.y;
			if(skinGuideBtn)
			{
				skinGuideBtn.x = GlobalDef.GameStage.stageWidth - skinGuideBtn.width - 15;
				skinGuideBtn.y = GlobalDef.GameStage.stageHeight - 115;
			}
		}
		/**
		 * 显示名字选择
		 * 
		 */		
		public function showNameSelectPanel():void
		{
			settingMC1.visible = true;
			nameSettingPanel.fadeIn();
			settingMC2.visible = false;
			settingMC3.visible = false;
			settingMC4.visible = false;
		}
		/**
		 * 显示国家选择
		 * 
		 */		
		public function showCountrySelectPanel():void
		{
			settingMC1.visible = false;
			settingMC2.visible = true;
			countrySettingPanel.fadeIn();
			settingMC3.visible = false;
			settingMC4.visible = false;
			if(skinGuideBtn)
			{
				GlobalDef.GameStage.addChild(skinGuideBtn);
			}
		}
		/**
		 * 
		 * 显示队徽选择
		 */		
		public function showTeamIconSelectPanel():void
		{
			settingMC1.visible = false;
			settingMC2.visible = false;
			settingMC3.visible = true;
			teamIconSettingPanel.fadeIn();
			settingMC4.visible = false;
		}
		/**
		 * 显示位置选择
		 * 
		 */		
		public function showPlaceSelectPanel():void
		{
			settingMC1.visible = false;
			settingMC2.visible = false;
			settingMC3.visible = false;
			settingMC4.visible = true;
			placeSettingPanel.fadeIn();
			placeSettingPanel.setName();
		}
		/**
		 * 
		 * 删除事件
		 */		
		public function removeEvtListener():void
		{
			GlobalDef.GameStage.removeEventListener(Event.RESIZE,resizeHandler);
			skinGuideBtn.removeEventListener(MouseEvent.CLICK,skinBthH);
		}
		/**
		 * 销毁
		 */		
		public function destroyView():void
		{
			removeEvtListener();
			nameSettingPanel.destroyView();
			countrySettingPanel.destroyView();
			teamIconSettingPanel.destroyView();
			placeSettingPanel.destroyView();
			if(this.parent)
			{
				this.parent.removeChild(this);
			}
			if(skinGuideBtn && skinGuideBtn.parent)
			{
				skinGuideBtn.parent.removeChild(skinGuideBtn);
			}
		}
	}
}